
<div id="page-content">
	<div class="col-lg-12">
		<div class="panel">
			<div class="panel-heading">
				<h3 class="panel-title" style="text-align:center;">
					#@installPJaxGoBackBtn()
					添加新指标
				</h3>
			</div>
			<form id="editForm" class="panel-body form-horizontal form-padding">
				<div class="form-group">
					<label class="col-md-3 control-label">父级指标项</label>
					<div class="col-md-5">
						<div class="input-group mar-btm">
							<input type="text" id="pName" value="#(p?p.name:'根目录')" readonly class="form-control">
							<input type="hidden" id ="pId" name="paperBase.parent_id"  value="#(p?p.id:'#root')">
							<input type="hidden" id = "menuId" name="paperBase.id" value="#(m?m.id:'')">

							<span class="input-group-btn">
			                            <button class="btn btn-mint" type="button" onclick="selectOneMenu()">选择</button>
			                        </span>
						</div>
						<small class="help-block">请选择</small>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-3 control-label">指标名称</label>
					<div class="col-md-5">
						<input type="text"  name="paperBase.name" class="form-control"  value="#(m?m.name:'')">
						<small class="help-block">请输入指标名称</small>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-3 control-label">指标权重</label>
					<div class="col-md-5">
						<input type="text"  onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"  name="paperBase.code" class="form-control"  value="#(m?m.code:'')">
						<small class="help-block">请输入指标权重</small>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-3 control-label" for="demo-textarea-input">描述信息</label>
					<div class="col-md-5">
						<textarea name="paperBase.description" rows="9" class="form-control">#(m?m.description:'')</textarea>
						<small class="help-block">请输入描述信息</small>
					</div>
				</div>
				<!--<div class="form-group">
					<label class="col-md-3 control-label">是否启用</label>
					<div class="col-md-5" style="line-height: 30px;">
						<input  type="checkbox" id="IfStart" name="paperBase.if_start"  value="1" #if(m&&m.if_show=='1') checked #end >
					</div>
				</div>-->
				<div class="form-group">
					<label class="col-md-3 control-label">显示顺序</label>
					<div class="col-md-5">
						<input type="text" name="paperBase.sort" class="form-control" value="#(m?m.sort:'')">
						<small class="help-block">请输入显示顺序</small>
					</div>
				</div>
				<div class="panel-footer">
					<div class="row">
						<div class="col-sm-9 col-sm-offset-3">
							<button class="btn btn-warning" type="reset">重置</button>
							<button class="btn btn-mint" type="submit" >保存</button>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<script>
	function save(){
		var data = common_ajax.ajaxFunc("/admin/paperbase/save", $('#editForm').serialize(), "json", null);
		if(data.success){
			pointLion.alertMsg("保存成功!" , "success" , "small" , function(){
				doPjax(ctx+'/admin/paperbase/getListPage');//跳转到列表页
			});
		}
	}
	//选择一个父级菜单
	var selectedNode={};
	function selectOneMenu(){
		layer.open({
			type: 2,
			title: false, //不显示标题栏
			area: ['370px', '550px'],
			shade: 0.2,
			id: 'selectOneMenu', //设定一个id，防止重复弹出
			resize: false,
			closeBtn: false,
			isOutAnim : false ,
			btn: ['确定', '取消'],
			btnAlign: 'c',
			content: ctx+'/admin/paperbase/getSelectOneItmePage',
			success: function(layero){

			},
			yes: function(){
				var thisId = $("#menuId").val();//主键
				if(thisId==selectedNode.id){
					layer.closeAll();
					pointLion.alertMsg("您不能选择自己为父级节点!" , "warning" , "small" , null);
					return;
				}
				$("#pName").val(selectedNode.name);//所选单位名称
				$("#pId").val(selectedNode.id);//所选单位id
				layer.closeAll();
			}
		});
	}
	function setOneMenuNode(node){
		selectedNode = node;
	}


	$(document).ready(function() {
		//new Switchery(document.getElementById('IfStart'));//制做开关按钮
		$('#editForm').bootstrapValidator({
			fields: {
				"paperBase.name": {
					validators: {
						notEmpty: {
							message: '*名称不能为空'
						},
						stringLength: {/*长度提示*/
							max: 50,
							message: '*名称长度必须小于50'
						}
					}
				},
				"paperBase.sort": {
					validators: {
						lessThan: {
							inclusive:true,
							value: 99,
							message: '*请输入小于99的数字'
						}
					}
				}
			}
		}).on("success.form.bv", function (e) {
			save();
			return false;//阻止表单跳转
		});
	});
</script>